<template>
  <el-dialog
      v-model="ledgerEditWinDialog"
      title="编辑台账"
      width="50%">
    <template #default>
      <el-form :model="editSetting" label-width="auto">
        <el-form-item label="仓库编码">
          <el-input v-model="editSetting.storeCode"/>
        </el-form-item>
        <el-form-item label="仓库名称">
          <el-input v-model="editSetting.storeName"/>
        </el-form-item>
        <el-form-item label="位置">
          <el-input v-model="editSetting.storePosition"/>
        </el-form-item>
        <el-form-item label="面积">
          <el-input v-model="editSetting.storeAreas"/>
        </el-form-item>
        <el-form-item label="负责人">
          <el-input v-model="editSetting.storePersonName"/>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="editSetting.storeNotes"/>
        </el-form-item>
      </el-form>
    </template>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="editSettingSubmit">
          提交
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>

import {onMounted, ref, watch} from "vue";
import ledgerRequest from "@/api/ledger.js";
import {ElMessage} from "element-plus";
import storeRequest from "@/api/store.js";
const props = defineProps(['storeId']);
const emits = defineEmits(['editComplate']);
let ledgerEditWinDialog = ref(false);
let editSetting = ref({});
let workShops = ref({});

function cancel(){
  editSetting = ref({});
  ledgerEditWinDialog.value =false;
}
function editSettingSubmit(){
  storeRequest.updateSetting(editSetting.value,res=>{
    if (res.code == 200){
      ElMessage({
        type:"success",
        message:"修改成功"
      });
      cancel()
      emits('editComplate');
    }else {
      ElMessage({
        type:"warning",
        message:"修改失败"
      })
    }
  })
}

function loadStoreById(){
  storeRequest.selectById(props.storeId,res=>{
    if (res.data){
      editSetting.value =res.data;
      ledgerEditWinDialog.value = true;
    }
  })
}

watch(()=>props.storeId,()=>{
  if(props.storeId){
    loadStoreById();
  }
});



</script>

<style scoped>

</style>